<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"><xsl:key name="services-by-user" match="USER" use="USER_ID"/><xsl:template match="AUTHORIZEDUSERS"><AUTHORIZEDUSERS><xsl:for-each select="USER[count(. | key('services-by-user', USER_ID)[1]) = 1]"><xsl:sort select="SERVICE_ID"/><USER><USERID><xsl:value-of select="USER_ID"/></USERID><FIRST_NAME><xsl:value-of select="FIRST_NAME"/></FIRST_NAME><LAST_NAME><xsl:value-of select="LAST_NAME"/></LAST_NAME><STATUS>ORIGINAL</STATUS><BINDINGS><xsl:for-each select="key('services-by-user', USER_ID)"><xsl:sort select="USER_ID"/><BINDING><SERVICEID><xsl:value-of select="SERVICE_ID"/></SERVICEID><SERVICE_NAME><xsl:value-of select="SERVICE_NAME"/></SERVICE_NAME></BINDING></xsl:for-each></BINDINGS></USER></xsl:for-each></AUTHORIZEDUSERS></xsl:template></xsl:stylesheet>
